\documentclass[12pt]{article}

\usepackage{amsmath}    % need for subequations
\usepackage{graphicx}   % need for figures
\usepackage{verbatim}   % useful for program listings
\usepackage{color}      % use if color is used in text
\usepackage{subfigure}  % use for side-by-side figures
\usepackage{hyperref}   % use for hypertext links, including those to external documents and URLs

% don't need the following. simply use defaults
\setlength{\baselineskip}{16.0pt}    % 16 pt usual spacing between lines

\setlength{\parskip}{3pt plus 2pt}
\setlength{\parindent}{20pt}
\setlength{\oddsidemargin}{0.5cm}
\setlength{\evensidemargin}{0.5cm}
\setlength{\marginparsep}{0.75cm}
\setlength{\marginparwidth}{2.5cm}
\setlength{\marginparpush}{1.0cm}
\setlength{\textwidth}{150mm}

\begin{comment}
  \pagestyle{empty} % use if page numbers not wanted
\end{comment}

% above is the preamble

\begin{document}

\begin{center}
  {\large Introduction to \LaTeX} \\ % \\ = new line
  \copyright 2006 by Harvey Gould \\
  December 5, 2006
\end{center}

\section{Introduction}
\TeX\ looks more difficult than it is. It is
almost as easy as $\pi$. See how easy it is to make special
symbols such as $\alpha$,
$\beta$, $\gamma$,
$\delta$, $\sin x$, $\hbar$, $\lambda$, $\ldots$ We also can make
subscripts
$A_{x}$, $A_{xy}$ and superscripts, $e^x$, $e^{x^2}$, and
$e^{a^b}$. We will use \LaTeX, which is based on \TeX\ and has
many higher-level commands (macros) for formatting, making
tables, etc. More information can be found in Ref.~\cite{latex}.

We just made a new paragraph. Extra lines and spaces make no
difference. Note that all formulas are enclosed by
\$ and occur in \textit{math mode}.

The default font is Computer Modern. It includes \textit{italics},
\textbf{boldface},
\textsl{slanted}, and \texttt{monospaced} fonts.

\section{Equations}
Let us see how easy it is to write equations.
\begin{equation}
  \Delta =\sum_{i=1}^N w_i (x_i - \bar{x})^2 .
\end{equation}
It is a good idea to number equations, but we can have a
equation without a number by writing
\begin{equation}
  P(x) = \frac{x - a}{b - a} , \nonumber
\end{equation}
and
\begin{equation}
  g = \frac{1}{2} \sqrt{2\pi} . \nonumber
\end{equation}

We can give an equation a label so that we can refer to it later.
\begin{equation}
  \label{eq:ising}
  E = -J \sum_{i=1}^N s_i s_{i+1} ,
\end{equation}
Equation~\eqref{eq:ising} expresses the energy of a configuration
of spins in the Ising model.\footnote{It is necessary to process (typeset) a
file twice to get the counters correct.}

We can define our own macros to save typing. For example, suppose
that we introduce the macros:
\begin{verbatim}
 \newcommand{\lb}{{\langle}}
 \newcommand{\rb}{{\rangle}}
\end{verbatim}
\newcommand{\lb}{{\langle}}
\newcommand{\rb}{{\rangle}}
Then we can write the average value of $x$ as
\begin{verbatim}
\begin{equation}
\lb x \rb = 3
\end{equation}
\end{verbatim}
The result is
\begin{equation}
  \lb x \rb = 3 .
\end{equation}

Examples of more complicated equations:
\begin{equation}
  I = \! \int_{-\infty}^\infty f(x)\,dx \label{eq:fine}.
\end{equation}
We can do some fine tuning by adding small amounts of horizontal
spacing:
\begin{verbatim}
 \, small space       \! negative space
\end{verbatim}
as is done in Eq.~\eqref{eq:fine}.

We also can align several equations:
\begin{align}
  a & = b \\
  c &= d ,
\end{align}
or number them as subequations:
\begin{subequations}
  \begin{align}
    a & = b \\
    c &= d .
  \end{align}
\end{subequations}

We can also have different cases:
\begin{equation}
  \label{eq:mdiv}
  m(T) =
  \begin{cases}
  0 & \text{$T > T_c$} \\
\bigl(1 - [\sinh 2 \beta J]^{-4} \bigr)^{\! 1/8} & \text{$T < T_c$}
\end{cases}
\end{equation}
write matrices
\begin{align}
  \textbf{T} &=
  \begin{pmatrix}
    T_{++} \hfill & T_{+-} \\
    T_{-+} & T_{--} \hfill 
  \end{pmatrix} , \nonumber \\
  & =
  \begin{pmatrix}
    e^{\beta (J + B)} \hfill & e^{-\beta J} \hfill \\
    e^{-\beta J} \hfill & e^{\beta (J - B)} \hfill
  \end{pmatrix}.
\end{align}
and 
\newcommand{\rv}{\textbf{r}}
\begin{equation}
  \sum_i \vec A \cdot \vec B = -P\!\int\! \rv \cdot
  \hat{\mathbf{n}}\, dA = P\!\int \! {\vec \nabla} \cdot \rv\, dV.
\end{equation}

\section{Tables}
Tables are a little more difficult. TeX
automatically calculates the width of the columns.

\begin{table}[h]
  \begin{center}
    \begin{tabular}{|l|l|r|l|}
      \hline
      lattice & $d$ & $q$ & $T_{\rm mf}/T_c$ \\
      \hline
      square & 2 & 4 & 1.763 \\
      \hline
      triangular & 2 & 6 & 1.648 \\
      \hline
      diamond & 3 & 4 & 1.479 \\
      \hline
      simple cubic & 3 & 6 & 1.330 \\
      \hline
      bcc & 3 & 8 & 1.260 \\
      \hline
      fcc & 3 & 12 & 1.225 \\
      \hline
    \end{tabular}
    \caption{\label{tab:5/tc}Comparison of the mean-field predictions
      for the critical temperature of the Ising model with exact results
      and the best known estimates for different spatial dimensions $d$
    and lattice symmetries.}
  \end{center}
\end{table}

\section{Lists}

Some example of formatted lists include the
following:

\begin{enumerate}

  \item bread

  \item cheese

\end{enumerate}

\begin{itemize}

  \item Tom

  \item Dick

\end{itemize}

\section{Figures}

We can make figures bigger or smaller by scaling them. Figure~\ref{fig:lj}
has been scaled by 60\%.

\begin{figure}[h]
  \begin{center}
    \includegraphics{figures/sine}
    \caption{\label{fig:typical}Show me a sine.}
  \end{center}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \scalebox{0.6}{\includegraphics{figures/lj}}
    \caption{\label{fig:lj}Plot of the
      Lennard-Jones potential
      $u(r)$. The potential is characterized by a length
      $\sigma$ and an energy
    $\epsilon$.}
  \end{center}
\end{figure}

\section{Literal text}
It is desirable to print program code exactly as it is typed in a
monospaced font. Use \verb \begin{verbatim} and
\verb \end{verbatim} as in the following example:
\begin{verbatim}
double y0 = 10; // example of declaration and assignment statement
double v0 = 0;  // initial velocity
double t = 0;   // time
double dt = 0.01; // time step
double y = y0;
\end{verbatim}
The command \verb \verbatiminput{programs/Square.java}\ allows
you to list the file \texttt{Square.java} in the directory
programs.

\section{Special Symbols}

\subsection{Common Greek letters}

These commands may be used only in math mode. Only the most common
letters are included here.

$\alpha, 
\beta, \gamma, \Gamma,
\delta,\Delta,
\epsilon, \zeta, \eta, \theta, \Theta, \kappa,
\lambda, \Lambda, \mu, \nu,
\xi, \Xi,
\pi, \Pi,
\rho,
\sigma, 
\tau,
\phi, \Phi,
\chi,
\psi, \Psi,
\omega, \Omega$

\subsection{Special symbols}

The derivative is defined as
\begin{equation}
  \frac{dy}{dx} = \lim_{\Delta x \to 0} \frac{\Delta y}
  {\Delta x}
\end{equation}
\begin{equation}
  f(x) \to y \quad \mbox{as} \quad x \to
  x_{0}
\end{equation}
\begin{equation}
  f(x) \mathop {\longrightarrow}
  \limits_{x \to x_0} y
\end{equation}

\noindent Order of magnitude:
\begin{equation}
  \log_{10}f \simeq n
\end{equation}
\begin{equation}
  f(x)\sim 10^{n}
\end{equation}
Approximate equality:
\begin{equation}
  f(x)\simeq g(x)
\end{equation}
\LaTeX\ is simple if we keep everything in proportion:
\begin{equation}
  f(x) \propto x^3 .
\end{equation}

Finally we can skip some space by using commands such as
\begin{verbatim}
\bigskip    \medskip    \smallskip    \vspace{1pc}
\end{verbatim}
The space can be negative.

\section{\color{red}Use of Color}

{\color{blue}{We can change colors for emphasis}},
{\color{green}{but}} {\color{cyan}{who is going pay for the ink?}}

\section{\label{morefig}Subfigures}

As soon as many students start becoming comfortable using \LaTeX, they want
to use some of its advanced features. So we now show how to place two
figures side by side.

\begin{figure}[h!]
  \begin{center}
    \subfigure[Real and imaginary.]{
    \includegraphics[scale=0.5]{figures/reim}}
    \subfigure[Amplitude and phase.]{
    \includegraphics[scale=0.5]{figures/phase}}
    \caption{\label{fig:qm/complexfunctions} Two representations of complex
    wave functions.}
  \end{center}
\end{figure}

We first have to include the necessary package,
\verb+\usepackage{subfigure}+, which has to go in the preamble (before
\verb+\begin{document}+). It sometimes can be difficult to place a figure in
the desired place.

Your LaTeX document can be easily modified to make a poster or a screen
presentation similar to (and better than) PowerPoint. Conversion to HTML is
straightforward. Comments on this tutorial are appreciated.

\begin{thebibliography}{5}

  \bibitem{latex}Helmut Kopka and Patrick W. Daly, \textsl{A Guide to
  \LaTeX: Document Preparation for Beginners and Advanced Users},
  fourth edition, Addison-Wesley (2004).

  \bibitem{website}Some useful links are
  given at \url{}.

\end{thebibliography}

{\small \noindent Updated 5 December 2006.}
\section{Introduction}

\latex is a typesetting program; given an input file with formatting
instructions (e.g intro.tex), the program will create your document in
one of several formats (DVI, Postscript or PDF).  It is therefore not
a WYSIWYG word processor.  \latex is known as a logical markup
language, similar for example to HTML, so that you describe a piece of
text as a ``section heading'' rather than saying that it should be
formatted in a certain way.  It has excellent facilities for
typesetting mathematics, and handles large documents (such as theses)
well.  The aim of this document is not to provide an overview of
\latex, since many other guides have already been written (see
Section~\ref{sec:summary}).  Instead, it has been written primarily to
provide simple workable examples that you can cut and paste to help
you get started with \latex.  The examples have been selected to be
those most likely to be useful when writing a scientific report.  This
document is best read by comparing the source code with the resulting
output.

\section{Running \latex}

The files to accompany this paper are at:
\url{http://www.damtp.cam.ac.uk/user/eglen/texintro}.  Get the
following files and put them into a new directory.

\begin{enumerate}
  \item \url{intro.tex}: the main \latex document.
  \item \url{example.bib}: a short bibliography.
  \item \url{sigmoid.ps}: example postscript image.
  \item \url{sigmoid.pdf}: example PDF image.
\end{enumerate}

Change directory to where you stored the files and type the
following (ignoring comments placed after \#\#):

\begin{verbatim}
latex intro                     ## Run latex 1st time.
bibtex intro                    ## Extract required references
latex intro                     ## Run latex 2nd to resolve references.
latex intro                     ## Probably need to run latex a 3rd time.
xdvi intro                      ## View the DVI (device independent) file.
dvips -o intro.ps intro         ## Create a postscript file for printing.
\end{verbatim}

You will notice that you run latex several times here; this is so that
references can be resolved, and references can be extracted from your
bibtex file.  After running latex, you will be told if you need to run
it again to resolve references.  After a while, you will get the idea
of how many times you need to run latex to resolve all your
references.

If instead you would like to generate PDF files (see
Section~\ref{sec:graphics} for a discussion of file formats for
included images), you can try the following shorter sequence:

\begin{verbatim}
pdflatex intro
bibtex intro
pdflatex intro
pdflatex intro
xpdf intro.pdf                  ## View the resulting PDF
\end{verbatim}

Whether you prefer to generate DVI or PDF is up to you.  The xdvi
viewer has some nice features, such as it can reload your document
easily and has a ``magnifying glass'' that is activated by the mouse.
On the other hand, xpdf will display the document more accurately as 
it will be printed.

\section{Tables}

Tables are relatively straightforward to generate.  Note that tables
and figures are not always placed exactly where you wish, as
they can \textit{float} to other parts of the document.  Rather than
trying to battle with \latex as to where they are placed, concentrate
first on getting the right content and let \latex worry about the
positioning.  Instead, use labels to your tables to refer to them.
See Table~\ref{tab:simple} and Table~\ref{tab:pars} for examples.

\begin{table}
  \centering
  \begin{tabular}{ccc}
    year & min temp (\textdegree C) & max temp (\textdegree C)\\ 
    \hline
    1970 & $-5$ & 35\\
    1975 & $-7$ & 29\\
    1980 & $-3$ & 30\\
    1985 & $-2$ & 32\\
  \end{tabular}
  \caption{Fictional minimal and maximal temperatures recorded in
  Cambridge over several years.}
  \label{tab:simple}
\end{table}
%% Why are the negative numbers above enclosed in math mode?
%% Hint: consider the difference between "-" in text and in math.

\begin{table}[htbp]
  \centering
  \begin{tabular}{lccc}\\ \hline
    & \multicolumn{1}{c}{$\phi$ (\micro m)}
    & \multicolumn{1}{c}{$\alpha$}
    & $\delta_{12}$ (\micro m)\\ \hline
    W81S1\\
    $h_{11}(u)$  & 67.94 & 7.81\\
    $h_{22}(u)$  & 66.27 & 5.40\\
    $h_{12}(u)$  &       &     &18\\
    \hline
    M623\\
    $h_{11}(u)$  &112.79 &  3.05\\
    $h_{22}(u)$  & 65.46 &  8.11\\
    $h_{12}(u)$  &       &      &20\\
    \hline
  \end{tabular}
  \caption{Summary of parameter estimates for the univariate
    functions $h_{11}(u)$, $h_{22}(u)$ and the bivariate function
    $h_{12}(u)$.  For the univariate fits, $\alpha$ and $\phi$ are 
    least-square estimates (assuming $\delta$ was fixed at 15 \micro m).
    The final column gives the
    maximum likelihood estimate of $\delta_{12}$ assuming that the
    interaction between types is simple inhibition.
  \label{tab:pars}}
\end{table}


\section{Bibliography management}

Scientific reports normally require a section where your references
are listed.  Bibtex is an excellent system for maintaining references,
especially for large documents.  Each reference needs a unique key;
you can then refer to the reference in your \latex document by using
this key within a cite command.

Take care when formatting your references, especially when it comes to
writing authors names and the case of letters in journal titles.  In
our examples, the files are found in \url{example.bib}.  As an example
of a citation, see \citep{ihaka1996} or \citep{ihaka1996,venables1999}.

Bibtex is flexible enough to format your references in a wide number
of different styles to suit your needs.  In this file I have used the
``natbib'' package, which is suitable for the natural sciences.
Depending on the type of cite command you get (and the package that
you use for citations), you can get different styles of citation.  See
Table~\ref{tab:cite} for some examples.

\begin{table}
  \centering
  \begin{tabular}{ll}
    \hline
    command & result\\ \hline
    \verb+\citep{ihaka1996}+ & \citep{ihaka1996}\\
    \verb+\citet{ihaka1996}+ & \citet{ihaka1996}\\
    \verb+\citep[see][p. 300]{ihaka1996}+ &
    \citep[see][p. 300]{ihaka1996}
    \\
    \verb+\citeauthor{ihaka1996}+ & \citeauthor{ihaka1996}
    \\
    \verb+\citeyear{ihaka1996}+ & \citeyear{ihaka1996}
    \\
    \hline
  \end{tabular}
  \caption{Examples of different citation commands available in the
  natbib package.}
  \label{tab:cite}
\end{table}


\section{Graphics}
\label{sec:graphics}

\latex can include images in one of several format, depending on
whether you use latex (postscript format required) or pdflatex (either
jpeg, png or pdf required).  Figures can be included either at their
natural size, or you can specify e.g. the figure width.
Figure~\ref{fig:example} shows an example image which intentionally
looks slightly different depending on whether you compile the document
with latex or pdflatex.  Note that in this example the suffix of the
image file is not included so that this document compiles under both
latex and pdflatex.

\begin{figure}
  \centering
  \includegraphics[width=6cm]{sigmoid}
  \caption{Example of a sigmoidal curve generated by the R programming
    environment.  The title above the curve indicates whether you have
  included the postscript or the pdf version of the figure.}
  \label{fig:example}
\end{figure}

\section{Mathematics}

\latex can format mathematics with ease, either in line, such as 
$x \times y$, or on separate lines, such as:
\[ x^2 +y^2 = z^2 \]

If you are writing several lines of equations, you can use statements
like the following:

\begin{align}
  b(t) & = s(t) - \int_{0}^{T} a(t') \cdot i(T-t') dt'
  \\
  a(t) & = \int_{0}^{T} b(t) \cdot e(T-t') dt' \label{eq:am}
  \\
  g(t) & = b(t) \ast e(t) \nonumber
\end{align}

By using labels on certain equations, we can refer to equations by
number, such as equation~(\ref{eq:am}).

\section{Summary}
\label{sec:summary}
This short guide should give you a flavour of what can be done with
\latex.  It is by no means complete, or supposed to be
self-explanatory.  It is, however, hopefully enough to get you
started!  Try experimenting by editing the source file and then
recompiling this document.  As mentioned earlier, there are many
guides for latex.  Two that I can recommend are
\url{http://www.andy-roberts.net/misc/latex/index.html} and 
`` The (Not So) Short Introduction to LaTeX2e''
(\url{http://ctan.tug.org/tex-archive/info/lshort/english/lshort.pdf}).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Finally we specify the format required for our references and the
%% name of the bibtex file where our references should be taken from.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\bibliographystyle{plainnat}
\bibliography{example}

\section{Introduction}
\TeX\ looks more difficult than it is. It is
almost as easy as $\pi$. See how easy it is to make special
symbols such as $\alpha$,
$\beta$, $\gamma$,
$\delta$, $\sin x$, $\hbar$, $\lambda$, $\ldots$ We also can make
subscripts
$A_{x}$, $A_{xy}$ and superscripts, $e^x$, $e^{x^2}$, and
$e^{a^b}$. We will use \LaTeX, which is based on \TeX\ and has
many higher-level commands (macros) for formatting, making
tables, etc. More information can be found in Ref.~\cite{latex}.

We just made a new paragraph. Extra lines and spaces make no
difference. Note that all formulas are enclosed by
\$ and occur in \textit{math mode}.

The default font is Computer Modern. It includes \textit{italics},
\textbf{boldface},
\textsl{slanted}, and \texttt{monospaced} fonts.

\section{Equations}
Let us see how easy it is to write equations.
\begin{equation}
  \Delta =\sum_{i=1}^N w_i (x_i - \bar{x})^2 .
\end{equation}
It is a good idea to number equations, but we can have a
equation without a number by writing
\begin{equation}
  P(x) = \frac{x - a}{b - a} , \nonumber
\end{equation}
and
\begin{equation}
  g = \frac{1}{2} \sqrt{2\pi} . \nonumber
\end{equation}

We can give an equation a label so that we can refer to it later.
\begin{equation}
  \label{eq:ising}
  E = -J \sum_{i=1}^N s_i s_{i+1} ,
\end{equation}
Equation~\eqref{eq:ising} expresses the energy of a configuration
of spins in the Ising model.\footnote{It is necessary to process (typeset) a
file twice to get the counters correct.}

We can define our own macros to save typing. For example, suppose
that we introduce the macros:
\begin{verbatim}
 \newcommand{\lb}{{\langle}}
 \newcommand{\rb}{{\rangle}}
\end{verbatim}
\newcommand{\lb}{{\langle}}
\newcommand{\rb}{{\rangle}}
Then we can write the average value of $x$ as
\begin{verbatim}
\begin{equation}
\lb x \rb = 3
\end{equation}
\end{verbatim}
The result is
\begin{equation}
  \lb x \rb = 3 .
\end{equation}

Examples of more complicated equations:
\begin{equation}
  I = \! \int_{-\infty}^\infty f(x)\,dx \label{eq:fine}.
\end{equation}
We can do some fine tuning by adding small amounts of horizontal
spacing:
\begin{verbatim}
 \, small space       \! negative space
\end{verbatim}
as is done in Eq.~\eqref{eq:fine}.

We also can align several equations:
\begin{align}
  a & = b \\
  c &= d ,
\end{align}
or number them as subequations:
\begin{subequations}
  \begin{align}
    a & = b \\
    c &= d .
  \end{align}
\end{subequations}

We can also have different cases:
\begin{equation}
  \label{eq:mdiv}
  m(T) =
  \begin{cases}
  0 & \text{$T > T_c$} \\
\bigl(1 - [\sinh 2 \beta J]^{-4} \bigr)^{\! 1/8} & \text{$T < T_c$}
\end{cases}
\end{equation}
write matrices
\begin{align}
  \textbf{T} &=
  \begin{pmatrix}
    T_{++} \hfill & T_{+-} \\
    T_{-+} & T_{--} \hfill 
  \end{pmatrix} , \nonumber \\
  & =
  \begin{pmatrix}
    e^{\beta (J + B)} \hfill & e^{-\beta J} \hfill \\
    e^{-\beta J} \hfill & e^{\beta (J - B)} \hfill
  \end{pmatrix}.
\end{align}
and 
\newcommand{\rv}{\textbf{r}}
\begin{equation}
  \sum_i \vec A \cdot \vec B = -P\!\int\! \rv \cdot
  \hat{\mathbf{n}}\, dA = P\!\int \! {\vec \nabla} \cdot \rv\, dV.
\end{equation}

\section{Tables}
Tables are a little more difficult. TeX
automatically calculates the width of the columns.

\begin{table}[h]
  \begin{center}
    \begin{tabular}{|l|l|r|l|}
      \hline
      lattice & $d$ & $q$ & $T_{\rm mf}/T_c$ \\
      \hline
      square & 2 & 4 & 1.763 \\
      \hline
      triangular & 2 & 6 & 1.648 \\
      \hline
      diamond & 3 & 4 & 1.479 \\
      \hline
      simple cubic & 3 & 6 & 1.330 \\
      \hline
      bcc & 3 & 8 & 1.260 \\
      \hline
      fcc & 3 & 12 & 1.225 \\
      \hline
    \end{tabular}
    \caption{\label{tab:5/tc}Comparison of the mean-field predictions
      for the critical temperature of the Ising model with exact results
      and the best known estimates for different spatial dimensions $d$
    and lattice symmetries.}
  \end{center}
\end{table}

\section{Lists}

Some example of formatted lists include the
following:

\begin{enumerate}

  \item bread

  \item cheese

\end{enumerate}

\begin{itemize}

  \item Tom

  \item Dick

\end{itemize}

\section{Figures}

We can make figures bigger or smaller by scaling them. Figure~\ref{fig:lj}
has been scaled by 60\%.

\begin{figure}[h]
  \begin{center}
    \includegraphics{figures/sine}
    \caption{\label{fig:typical}Show me a sine.}
  \end{center}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \scalebox{0.6}{\includegraphics{figures/lj}}
    \caption{\label{fig:lj}Plot of the
      Lennard-Jones potential
      $u(r)$. The potential is characterized by a length
      $\sigma$ and an energy
    $\epsilon$.}
  \end{center}
\end{figure}

\section{Literal text}
It is desirable to print program code exactly as it is typed in a
monospaced font. Use \verb \begin{verbatim} and
\verb \end{verbatim} as in the following example:
\begin{verbatim}
double y0 = 10; // example of declaration and assignment statement
double v0 = 0;  // initial velocity
double t = 0;   // time
double dt = 0.01; // time step
double y = y0;
\end{verbatim}
The command \verb \verbatiminput{programs/Square.java}\ allows
you to list the file \texttt{Square.java} in the directory
programs.

\section{Special Symbols}

\subsection{Common Greek letters}

These commands may be used only in math mode. Only the most common
letters are included here.

$\alpha, 
\beta, \gamma, \Gamma,
\delta,\Delta,
\epsilon, \zeta, \eta, \theta, \Theta, \kappa,
\lambda, \Lambda, \mu, \nu,
\xi, \Xi,
\pi, \Pi,
\rho,
\sigma, 
\tau,
\phi, \Phi,
\chi,
\psi, \Psi,
\omega, \Omega$

\subsection{Special symbols}

The derivative is defined as
\begin{equation}
  \frac{dy}{dx} = \lim_{\Delta x \to 0} \frac{\Delta y}
  {\Delta x}
\end{equation}
\begin{equation}
  f(x) \to y \quad \mbox{as} \quad x \to
  x_{0}
\end{equation}
\begin{equation}
  f(x) \mathop {\longrightarrow}
  \limits_{x \to x_0} y
\end{equation}

\noindent Order of magnitude:
\begin{equation}
  \log_{10}f \simeq n
\end{equation}
\begin{equation}
  f(x)\sim 10^{n}
\end{equation}
Approximate equality:
\begin{equation}
  f(x)\simeq g(x)
\end{equation}
\LaTeX\ is simple if we keep everything in proportion:
\begin{equation}
  f(x) \propto x^3 .
\end{equation}

Finally we can skip some space by using commands such as
\begin{verbatim}
\bigskip    \medskip    \smallskip    \vspace{1pc}
\end{verbatim}
The space can be negative.

\section{\color{red}Use of Color}

{\color{blue}{We can change colors for emphasis}},
{\color{green}{but}} {\color{cyan}{who is going pay for the ink?}}

\section{\label{morefig}Subfigures}

As soon as many students start becoming comfortable using \LaTeX, they want
to use some of its advanced features. So we now show how to place two
figures side by side.

\begin{figure}[h!]
  \begin{center}
    \subfigure[Real and imaginary.]{
    \includegraphics[scale=0.5]{figures/reim}}
    \subfigure[Amplitude and phase.]{
    \includegraphics[scale=0.5]{figures/phase}}
    \caption{\label{fig:qm/complexfunctions} Two representations of complex
    wave functions.}
  \end{center}
\end{figure}

We first have to include the necessary package,
\verb+\usepackage{subfigure}+, which has to go in the preamble (before
\verb+\begin{document}+). It sometimes can be difficult to place a figure in
the desired place.

Your LaTeX document can be easily modified to make a poster or a screen
presentation similar to (and better than) PowerPoint. Conversion to HTML is
straightforward. Comments on this tutorial are appreciated.

\begin{thebibliography}{5}

  \bibitem{latex}Helmut Kopka and Patrick W. Daly, \textsl{A Guide to
  \LaTeX: Document Preparation for Beginners and Advanced Users},
  fourth edition, Addison-Wesley (2004).

  \bibitem{website}Some useful links are
  given at \url{}.

\end{thebibliography}

{\small \noindent Updated 5 December 2006.}
\section{Introduction}

\latex is a typesetting program; given an input file with formatting
instructions (e.g intro.tex), the program will create your document in
one of several formats (DVI, Postscript or PDF).  It is therefore not
a WYSIWYG word processor.  \latex is known as a logical markup
language, similar for example to HTML, so that you describe a piece of
text as a ``section heading'' rather than saying that it should be
formatted in a certain way.  It has excellent facilities for
typesetting mathematics, and handles large documents (such as theses)
well.  The aim of this document is not to provide an overview of
\latex, since many other guides have already been written (see
Section~\ref{sec:summary}).  Instead, it has been written primarily to
provide simple workable examples that you can cut and paste to help
you get started with \latex.  The examples have been selected to be
those most likely to be useful when writing a scientific report.  This
document is best read by comparing the source code with the resulting
output.

\section{Running \latex}

The files to accompany this paper are at:
\url{http://www.damtp.cam.ac.uk/user/eglen/texintro}.  Get the
following files and put them into a new directory.

\begin{enumerate}
  \item \url{intro.tex}: the main \latex document.
  \item \url{example.bib}: a short bibliography.
  \item \url{sigmoid.ps}: example postscript image.
  \item \url{sigmoid.pdf}: example PDF image.
\end{enumerate}

Change directory to where you stored the files and type the
following (ignoring comments placed after \#\#):

\begin{verbatim}
latex intro                     ## Run latex 1st time.
bibtex intro                    ## Extract required references
latex intro                     ## Run latex 2nd to resolve references.
latex intro                     ## Probably need to run latex a 3rd time.
xdvi intro                      ## View the DVI (device independent) file.
dvips -o intro.ps intro         ## Create a postscript file for printing.
\end{verbatim}

You will notice that you run latex several times here; this is so that
references can be resolved, and references can be extracted from your
bibtex file.  After running latex, you will be told if you need to run
it again to resolve references.  After a while, you will get the idea
of how many times you need to run latex to resolve all your
references.

If instead you would like to generate PDF files (see
Section~\ref{sec:graphics} for a discussion of file formats for
included images), you can try the following shorter sequence:

\begin{verbatim}
pdflatex intro
bibtex intro
pdflatex intro
pdflatex intro
xpdf intro.pdf                  ## View the resulting PDF
\end{verbatim}

Whether you prefer to generate DVI or PDF is up to you.  The xdvi
viewer has some nice features, such as it can reload your document
easily and has a ``magnifying glass'' that is activated by the mouse.
On the other hand, xpdf will display the document more accurately as 
it will be printed.

\section{Tables}

Tables are relatively straightforward to generate.  Note that tables
and figures are not always placed exactly where you wish, as
they can \textit{float} to other parts of the document.  Rather than
trying to battle with \latex as to where they are placed, concentrate
first on getting the right content and let \latex worry about the
positioning.  Instead, use labels to your tables to refer to them.
See Table~\ref{tab:simple} and Table~\ref{tab:pars} for examples.

\begin{table}
  \centering
  \begin{tabular}{ccc}
    year & min temp (\textdegree C) & max temp (\textdegree C)\\ 
    \hline
    1970 & $-5$ & 35\\
    1975 & $-7$ & 29\\
    1980 & $-3$ & 30\\
    1985 & $-2$ & 32\\
  \end{tabular}
  \caption{Fictional minimal and maximal temperatures recorded in
  Cambridge over several years.}
  \label{tab:simple}
\end{table}
%% Why are the negative numbers above enclosed in math mode?
%% Hint: consider the difference between "-" in text and in math.

\begin{table}[htbp]
  \centering
  \begin{tabular}{lccc}\\ \hline
    & \multicolumn{1}{c}{$\phi$ (\micro m)}
    & \multicolumn{1}{c}{$\alpha$}
    & $\delta_{12}$ (\micro m)\\ \hline
    W81S1\\
    $h_{11}(u)$  & 67.94 & 7.81\\
    $h_{22}(u)$  & 66.27 & 5.40\\
    $h_{12}(u)$  &       &     &18\\
    \hline
    M623\\
    $h_{11}(u)$  &112.79 &  3.05\\
    $h_{22}(u)$  & 65.46 &  8.11\\
    $h_{12}(u)$  &       &      &20\\
    \hline
  \end{tabular}
  \caption{Summary of parameter estimates for the univariate
    functions $h_{11}(u)$, $h_{22}(u)$ and the bivariate function
    $h_{12}(u)$.  For the univariate fits, $\alpha$ and $\phi$ are 
    least-square estimates (assuming $\delta$ was fixed at 15 \micro m).
    The final column gives the
    maximum likelihood estimate of $\delta_{12}$ assuming that the
    interaction between types is simple inhibition.
  \label{tab:pars}}
\end{table}


\section{Bibliography management}

Scientific reports normally require a section where your references
are listed.  Bibtex is an excellent system for maintaining references,
especially for large documents.  Each reference needs a unique key;
you can then refer to the reference in your \latex document by using
this key within a cite command.

Take care when formatting your references, especially when it comes to
writing authors names and the case of letters in journal titles.  In
our examples, the files are found in \url{example.bib}.  As an example
of a citation, see \citep{ihaka1996} or \citep{ihaka1996,venables1999}.

Bibtex is flexible enough to format your references in a wide number
of different styles to suit your needs.  In this file I have used the
``natbib'' package, which is suitable for the natural sciences.
Depending on the type of cite command you get (and the package that
you use for citations), you can get different styles of citation.  See
Table~\ref{tab:cite} for some examples.

\begin{table}
  \centering
  \begin{tabular}{ll}
    \hline
    command & result\\ \hline
    \verb+\citep{ihaka1996}+ & \citep{ihaka1996}\\
    \verb+\citet{ihaka1996}+ & \citet{ihaka1996}\\
    \verb+\citep[see][p. 300]{ihaka1996}+ &
    \citep[see][p. 300]{ihaka1996}
    \\
    \verb+\citeauthor{ihaka1996}+ & \citeauthor{ihaka1996}
    \\
    \verb+\citeyear{ihaka1996}+ & \citeyear{ihaka1996}
    \\
    \hline
  \end{tabular}
  \caption{Examples of different citation commands available in the
  natbib package.}
  \label{tab:cite}
\end{table}


\section{Graphics}
\label{sec:graphics}

\latex can include images in one of several format, depending on
whether you use latex (postscript format required) or pdflatex (either
jpeg, png or pdf required).  Figures can be included either at their
natural size, or you can specify e.g. the figure width.
Figure~\ref{fig:example} shows an example image which intentionally
looks slightly different depending on whether you compile the document
with latex or pdflatex.  Note that in this example the suffix of the
image file is not included so that this document compiles under both
latex and pdflatex.

\begin{figure}
  \centering
  \includegraphics[width=6cm]{sigmoid}
  \caption{Example of a sigmoidal curve generated by the R programming
    environment.  The title above the curve indicates whether you have
  included the postscript or the pdf version of the figure.}
  \label{fig:example}
\end{figure}

\section{Mathematics}

\latex can format mathematics with ease, either in line, such as 
$x \times y$, or on separate lines, such as:
\[ x^2 +y^2 = z^2 \]

If you are writing several lines of equations, you can use statements
like the following:

\begin{align}
  b(t) & = s(t) - \int_{0}^{T} a(t') \cdot i(T-t') dt'
  \\
  a(t) & = \int_{0}^{T} b(t) \cdot e(T-t') dt' \label{eq:am}
  \\
  g(t) & = b(t) \ast e(t) \nonumber
\end{align}

By using labels on certain equations, we can refer to equations by
number, such as equation~(\ref{eq:am}).

\section{Summary}
\label{sec:summary}
This short guide should give you a flavour of what can be done with
\latex.  It is by no means complete, or supposed to be
self-explanatory.  It is, however, hopefully enough to get you
started!  Try experimenting by editing the source file and then
recompiling this document.  As mentioned earlier, there are many
guides for latex.  Two that I can recommend are
\url{http://www.andy-roberts.net/misc/latex/index.html} and 
`` The (Not So) Short Introduction to LaTeX2e''
(\url{http://ctan.tug.org/tex-archive/info/lshort/english/lshort.pdf}).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Finally we specify the format required for our references and the
%% name of the bibtex file where our references should be taken from.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\bibliographystyle{plainnat}
\bibliography{example}

\end{document}
